<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopCommissionRewardTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_commission_reward', ['comment' => '分销佣金', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('agent_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '分销商'])
            ->addColumn('buyer_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '购买人'])
            ->addColumn('order_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '订单'])
            ->addColumn('order_item_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '订单商品'])
            ->addColumn('commission_order_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '分销订单'])
            ->addColumn(Column::enum('type', ['money', 'score', 'change', 'bank', 'commission'])->setDefault('commission')->setComment('打款方式:commission=佣金钱包,money=余额钱包,score=积分,cash=现金(手动打款),change=企业付款到零钱,bank=企业付款到银行卡'))
            ->addColumn('commission', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '佣金'])
            ->addColumn('original_commission', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '原始佣金'])
            ->addColumn(Column::tinyInteger('commission_level')->setDefault(0)->setComment('执行层级'))
            ->addColumn('agent_level', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '执行等级'])
            ->addColumn('commission_rules', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '执行规则'])
            ->addColumn(Column::tinyInteger('status')->setDefault(0)->setComment('状态:-2=已退回,-1=已取消,0=待入账,1=已入账'))
            ->addColumn('commission_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '结算时间'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('commission_order_id')
            ->addIndex('agent_id')
            ->addIndex('buyer_id')
            ->create();
    }


    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_commission_reward');
        $table->drop();
    }
}
